package com.android.presenter.info;

import android.content.Context;
import android.text.TextUtils;

import com.android.model.entity.res.TradePWDVerifyResult;
import com.android.model.info.LocalSp;
import com.android.model.info.UserModel;
import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.presenter.iview.ITradePWDVerifyView;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 查询股票列表
 */

public class TradePasswordVerifyPresenter extends BasePresenter<ITradePWDVerifyView> {

    private static final String TAG = TradePasswordVerifyPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public TradePasswordVerifyPresenter(ITradePWDVerifyView iTradePWDVerifyView) {
        super(iTradePWDVerifyView);
        mUserModel = UserModel.getInstance();
    }

    public void verifyTradePassword(final Context context, String token, String password) {
        mUserModel.verifyTradePassword(token, password, new HttpObserver<TradePWDVerifyResult>() {
            @Override
            public void onSuccess(TradePWDVerifyResult tradePWDVerifyResult) {
                LogUtil.e(TAG, "查询成功！");
                if (mIView != null) {
                    mIView.createSSOTradePWDSuccess(tradePWDVerifyResult);
                    //存入ssoTradeToken
                    if (!TextUtils.isEmpty(tradePWDVerifyResult.getToken())) {
                        LocalSp.getInstance(context).saveSSOTradeToken(tradePWDVerifyResult.getToken());
                        LocalSp.getInstance(context).saveSSOTradeExpiredTime(tradePWDVerifyResult.getExpiredTime());
                    }
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.createSSOTradePWDFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
